using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class MenuDataController : MonoBehaviour
{
	public static MenuDataController instance;

	public List<level_info> levelinfo;

	public List<LevelStar> starinfo;

	public List<levellock> levellockinfo;

	public List<TDMData> tdmdata;

	public List<DTBData> dtbdata;

	public List<FFAData> ffadata;

	public List<SurData> surdata;

	public List<plane_buy> PlaneData;

	public List<weaopn_armour> ArmourData;

	public List<weapon_gun> MachineGunData;

	public List<weapon_gun> longmissileData;

	public List<weapon_gun> MultipleData;

	public List<weapon_miss> YoudaodanData;

	public List<PieceData> piecedata;

	public List<AchievementData> AchiData;

	public List<DailyData> DayData;

	public List<BoxData> Box_data;

	public List<BonusData> firstbonusdata;

	public List<BonusData> bonusdata;

	public List<LevelBox> levelboxdata;

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
	}

	public void list_join()
	{
		join_level_star();
	}

	public void join_level_star()
	{
		for (int i = 0; i < levelinfo.Count; i++)
		{
			for (int j = 0; j < levelinfo[i].starid.Count; j++)
			{
				if (levelinfo[i].starid[j] == -1)
				{
					continue;
				}
				for (int k = 0; k < starinfo.Count; k++)
				{
					if (levelinfo[i].starid[j] == starinfo[k].ID)
					{
						levelinfo[i].starid[j] = k;
						break;
					}
					if (k == starinfo.Count - 1)
					{
						UnityEngine.Debug.Log(" can not find the ID:level--star");
					}
				}
			}
		}
	}

	private void OnDestroy()
	{
		if (instance != null)
		{
			instance = null;
		}
	}

	public int Getplane_atk(int curplane)
	{
		int num = 0;
		int guntype = MenuPlayerprefs.instance.DS_Plane[curplane].guntype;
		num += MachineGunData[guntype].att[MenuPlayerprefs.instance.gunlock[guntype].curlv];
		guntype = MenuPlayerprefs.instance.DS_Plane[curplane].longtype;
		if (guntype != -1)
		{
			num += longmissileData[guntype].att[MenuPlayerprefs.instance.longlock[guntype].curlv];
		}
		guntype = MenuPlayerprefs.instance.DS_Plane[curplane].multipletype;
		if (guntype != -1)
		{
			num += MultipleData[guntype].att[MenuPlayerprefs.instance.multiplelock[guntype].curlv];
		}
		return num;
	}

	public int Getplane_def(int curplane)
	{
		int num = 0;
		int armourtype = MenuPlayerprefs.instance.DS_Plane[curplane].armourtype;
		return PlaneData[curplane].hp + ArmourData[armourtype].hp[MenuPlayerprefs.instance.armourlock[armourtype].curlv];
	}

	public void SetGlobalWeapon(int curplane)
	{
		int armourtype = MenuPlayerprefs.instance.DS_Plane[curplane].armourtype;
		GlobalInf.CurPlayerAtt.curheal.maxhp = PlaneData[curplane].hp + ArmourData[armourtype].hp[MenuPlayerprefs.instance.armourlock[armourtype].curlv];
		GlobalInf.CurPlayerAtt.curheal.def = ArmourData[armourtype].def[MenuPlayerprefs.instance.armourlock[armourtype].curlv];
		armourtype = MenuPlayerprefs.instance.DS_Plane[curplane].guntype;
		GlobalInf.CurPlayerAtt.curweapon.machgun = MachineGunData[armourtype].att[MenuPlayerprefs.instance.gunlock[armourtype].curlv];
		GlobalInf.CurPlayerAtt.curweapon.machgun_pen = MachineGunData[armourtype].pen[MenuPlayerprefs.instance.gunlock[armourtype].curlv];
		GlobalInf.CurPlayerAtt.curweapon.machgun_max = MachineGunData[armourtype].maxnum[MenuPlayerprefs.instance.gunlock[armourtype].curlv];
		GlobalInf.CurPlayerAtt.curweapon.machgun_fill_time = MachineGunData[armourtype].time[MenuPlayerprefs.instance.gunlock[armourtype].curlv];
		armourtype = MenuPlayerprefs.instance.DS_Plane[curplane].longtype;
		if (armourtype == -1)
		{
			GlobalInf.CurPlayerAtt.curweapon.missile_max = 0;
		}
		else
		{
			GlobalInf.CurPlayerAtt.curweapon.missile = longmissileData[armourtype].att[MenuPlayerprefs.instance.longlock[armourtype].curlv];
			GlobalInf.CurPlayerAtt.curweapon.missile_pen = longmissileData[armourtype].pen[MenuPlayerprefs.instance.longlock[armourtype].curlv];
			GlobalInf.CurPlayerAtt.curweapon.missile_max = longmissileData[armourtype].maxnum[MenuPlayerprefs.instance.longlock[armourtype].curlv];
			GlobalInf.CurPlayerAtt.curweapon.missile_fill_time = longmissileData[armourtype].time[MenuPlayerprefs.instance.longlock[armourtype].curlv];
		}
		armourtype = MenuPlayerprefs.instance.DS_Plane[curplane].multipletype;
		if (armourtype == -1)
		{
			GlobalInf.CurPlayerAtt.curweapon.missile_duo_max = 0;
		}
		else
		{
			GlobalInf.CurPlayerAtt.curweapon.missile_duo = MultipleData[armourtype].att[MenuPlayerprefs.instance.multiplelock[armourtype].curlv];
			GlobalInf.CurPlayerAtt.curweapon.missile_duo_pen = MultipleData[armourtype].pen[MenuPlayerprefs.instance.multiplelock[armourtype].curlv];
			GlobalInf.CurPlayerAtt.curweapon.missile_duo_max = MultipleData[armourtype].maxnum[MenuPlayerprefs.instance.multiplelock[armourtype].curlv];
			GlobalInf.CurPlayerAtt.curweapon.missile_duo_fill_time = MultipleData[armourtype].time[MenuPlayerprefs.instance.multiplelock[armourtype].curlv];
		}
		armourtype = MenuPlayerprefs.instance.DS_Plane[curplane].misstype;
		if (armourtype == -1)
		{
			GlobalInf.CurPlayerAtt.curweapon.youdaodan = 0;
		}
		else
		{
			GlobalInf.CurPlayerAtt.curweapon.youdaodan = YoudaodanData[armourtype].num;
		}
	}

	public PieceData Getpiece(int id)
	{
		for (int i = 0; i < piecedata.Count; i++)
		{
			if (piecedata[i].templateid == id)
			{
				return piecedata[i];
			}
		}
		return null;
	}

	public PieceData Getdroppiece(int id)
	{
		if (id < piecedata.Count)
		{
			return piecedata[id];
		}
		MonoBehaviour.print("not found piece!");
		return null;
	}

	public List<BoxData> Getboxdata()
	{
		return Box_data;
	}

	public List<gotoinfo> Getpiecelevel(int pieceindex)
	{
		List<gotoinfo> list = new List<gotoinfo>();
		gotoinfo item = default(gotoinfo);
		for (int i = 0; i < levelinfo.Count; i++)
		{
			if (levelinfo[i].dropitem[0].dropid == pieceindex)
			{
				item.curlv = i;
				if (MenuPlayerprefs.instance.curgamelevel >= i)
				{
					item.islock = false;
				}
				else
				{
					item.islock = true;
				}
				list.Add(item);
			}
			else if (levelinfo[i].dropitem[1].dropid == pieceindex)
			{
				item.curlv = i;
				if (MenuPlayerprefs.instance.curgamelevel >= i)
				{
					item.islock = false;
				}
				else
				{
					item.islock = true;
				}
				list.Add(item);
			}
		}
		return list;
	}

	public List<gotoinfo> Getpiecechallenge(int pieceindex)
	{
		List<gotoinfo> list = new List<gotoinfo>();
		gotoinfo item = default(gotoinfo);
		for (int i = 0; i < 3; i++)
		{
			if (dtbdata[i].challdata.dropitem.dropid == pieceindex)
			{
				item.curlv = -1;
				if (MenuPlayerprefs.instance.curgamelevel >= dtbdata[i].challdata.openlevel)
				{
					item.islock = false;
				}
				else
				{
					item.islock = true;
				}
				list.Add(item);
				break;
			}
		}
		for (int j = 0; j < 3; j++)
		{
			if (ffadata[j].challdata.dropitem.dropid == pieceindex)
			{
				item.curlv = -2;
				if (MenuPlayerprefs.instance.curgamelevel >= ffadata[j].challdata.openlevel)
				{
					item.islock = false;
				}
				else
				{
					item.islock = true;
				}
				list.Add(item);
				break;
			}
		}
		for (int k = 0; k < 3; k++)
		{
			if (surdata[k].challdata.dropitem.dropid == pieceindex)
			{
				item.curlv = -3;
				if (MenuPlayerprefs.instance.curgamelevel >= surdata[k].challdata.openlevel)
				{
					item.islock = false;
				}
				else
				{
					item.islock = true;
				}
				list.Add(item);
				break;
			}
		}
		for (int l = 0; l < 3; l++)
		{
			if (tdmdata[l].challdata.dropitem.dropid == pieceindex)
			{
				item.curlv = -4;
				if (MenuPlayerprefs.instance.curgamelevel >= tdmdata[l].challdata.openlevel)
				{
					item.islock = false;
				}
				else
				{
					item.islock = true;
				}
				list.Add(item);
				break;
			}
		}
		return list;
	}

	public List<PieceData> GetChallgePiece(int id)
	{
		List<PieceData> list = new List<PieceData>();
		List<int> list2 = new List<int>();
		int num = -1;
		switch (id)
		{
		case 6:
			for (int l = 0; l < surdata.Count; l++)
			{
				num = surdata[l].challdata.dropitem.dropid;
				if (list2.IndexOf(num) == -1)
				{
					list2.Add(num);
				}
			}
			break;
		case 7:
			for (int j = 0; j < tdmdata.Count; j++)
			{
				num = tdmdata[j].challdata.dropitem.dropid;
				if (list2.IndexOf(num) == -1)
				{
					list2.Add(num);
				}
			}
			break;
		case 8:
			for (int k = 0; k < dtbdata.Count; k++)
			{
				num = dtbdata[k].challdata.dropitem.dropid;
				if (list2.IndexOf(num) == -1)
				{
					list2.Add(num);
				}
			}
			break;
		case 9:
			for (int i = 0; i < ffadata.Count; i++)
			{
				num = ffadata[i].challdata.dropitem.dropid;
				if (list2.IndexOf(num) == -1)
				{
					list2.Add(num);
				}
			}
			break;
		}
		for (int m = 0; m < list2.Count; m++)
		{
			list.Add(piecedata[list2[m]]);
		}
		return list;
	}
}
